home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_shrinkmenu.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  99 lines

  1. /*
  2. **  GadTools layout toolkit
  3. **
  4. **  Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **      Freely distributable.
  6. **
  7. **  :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_MENUS    /* Support code */
  17.  
  18.     /* LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,UWORD Mask):
  19.      *
  20.      *  Rethink the widths of all menu items between First and Last, including
  21.      *  both the first and the last entry.
  22.      */
  23.  
  24. VOID
  25. LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,LONG Mask)
  26. {
  27.     ItemNode    *Here;
  28.     LONG         Width,MaxWidth = 0,CommandWidth = 0;
  29.  
  30.         // Determine the widths of all items, also calculate
  31.         // the command widths
  32.  
  33.     for(Here = First ; Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  34.     {
  35.         if((Here->Flags & ITEMF_IsSub) == Mask)
  36.         {
  37.             if(!(Here->Flags & ITEMF_IsBar))
  38.             {
  39.                 struct IntuiText *IntuiText = (struct IntuiText *)Here->Item.ItemFill;
  40.  
  41.                 Width = 2 + TextLength(&Root->RPort,IntuiText->IText,strlen(IntuiText->IText)) + 2;
  42.  
  43.                 if(Here->Item.Flags & CHECKIT)
  44.                     Width += 2 + Root->CheckWidth;
  45.  
  46.                 if(Width > MaxWidth)
  47.                     MaxWidth = Width;
  48.  
  49.                 if((Width = LTP_GetCommandWidth(Root,Here)) > CommandWidth)
  50.                     CommandWidth = Width;
  51.             }
  52.         }
  53.  
  54.         if(Here == Last)
  55.             break;
  56.     }
  57.  
  58.         // Now adjust the widths of all objects
  59.  
  60.     for(Here = First ; Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  61.     {
  62.         if((Here->Flags & ITEMF_IsSub) == Mask)
  63.         {
  64.             if(Here->Flags & ITEMF_IsBar)
  65.             {
  66.                 struct Image *Image = (struct Image *)Here->Item.ItemFill;
  67.  
  68.                 Image->Width = MaxWidth + CommandWidth - 4;
  69.             }
  70.             else
  71.             {
  72.                     // Move over the submenu items if necessary
  73.  
  74.                 if(Here->Item.SubItem)
  75.                 {
  76.                     ItemNode *Sub = (ItemNode *)((ULONG)Here->Item.SubItem - sizeof(struct MinNode));
  77.  
  78.                     FOREVER
  79.                     {
  80.                         Sub->Item.LeftEdge = MaxWidth + 2;
  81.  
  82.                         if(Sub->Item.NextItem)
  83.                             Sub = (ItemNode *)Sub->Node.mln_Succ;
  84.                         else
  85.                             break;
  86.                     }
  87.                 }
  88.             }
  89.  
  90.             Here->Item.Width = MaxWidth + CommandWidth;
  91.         }
  92.  
  93.         if(Here == Last)
  94.             break;
  95.     }
  96. }
  97.  
  98. #endif  /* DO_MENUS */
  99.